package com.xxgc.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xxgc.springboot.entity.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户 Mapper 接口
 * </p>
 *
 * @author Mr.Abel
 * @since 2022-09-27
 */
@Mapper
public interface UsersMapper extends BaseMapper<Users> {
    //根据用户id查询具体权限
    @Select("SELECT p.`perme` FROM `users` AS u,`roles` AS r,`role_and_perm` AS rap,`permissions` AS p \n" +
            "WHERE u.`role_id` = r.`id`  AND  r.`id` = rap.`r_id`  AND  p.`id` = rap.`p_id`  AND  u.`id` = #{id}")
    List<String> selectPermByUserId(int id);

    @Select("SELECT r.role FROM users AS u,roles AS r " +
            "WHERE u.role_id = r.id " +
            "AND u.id = #{id}")
    String selectRoleByUserId(int id);
}
